﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Tools
{
    public partial class Tool
    {

        /*
         
        /// <summary>
        /// 保存审核状态。
        /// </summary>
        protected void btnAudit_Click(object sender, EventArgs e)
        {
            string paymentIDListCurr = Methods.getSelectedValueForCheckBox(rptPaymentDetails, "chkAudit", "hidPaymentID", true);
            string paymentIDSource = ViewState["SourcePaymeytID"].ToString();

            string addPartID = Methods.getAddPart(paymentIDSource, paymentIDListCurr);
            string removePartID = Methods.getAddPart(paymentIDListCurr, paymentIDSource);


            BAudit bAudit = new BAudit();

            if (bAudit.AuditSingle1(addPartID, FSUser.UserID, FSUser.UserName, "1") && bAudit.AuditSingle1(removePartID, FSUser.UserID, FSUser.UserName, "0"))
            {
             //用组合ＳＱＬ语句的方法执行， update a set status=1 where name in('a,b,c,d,e')
                Jscript.ClientAlert(this, "操作成功！");
                getData();
            }
            else
            {
                Jscript.ClientAlert(this, "操作失败！");
            }
        }
         
         */



        /// <summary>
        /// repeater  里面加 checkbox
        /// 当用户选择完以后,判断改变了哪些,包括增加了哪些,减去了哪些.
        /// 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public static string getAddPart(string source, string target)
        {
            string[] arrTarget = target.Split(",".ToCharArray());

            string addPart = "";
            foreach (string s1 in arrTarget)
            {
                if (source.IndexOf(s1) < 0)
                {
                    if (addPart == "")
                    {
                        addPart += s1;
                    }
                    else
                    {
                        addPart += "," + s1;
                    }
                }
            }
            return addPart;
        }

        /// <summary>
        /// 返回 repeater 当中  所选中 radioButton  中的值。 
        /// </summary>
        /// <param name="rpt1"></param>
        /// <param name="controlName"></param>
        /// <returns></returns>
        public static string getSelectedRadioValue(Repeater rpt1, string controlName)
        {
            foreach (RepeaterItem item1 in rpt1.Items)
            {
                if (item1.FindControl(controlName) is System.Web.UI.HtmlControls.HtmlInputRadioButton)
                {
                    HtmlInputRadioButton rbtn1 = (HtmlInputRadioButton)item1.FindControl(controlName);
                    if (rbtn1.Checked)
                    {
                        return rbtn1.Value;
                    }
                }
            }
            return "";
        }


        /// <summary>
        /// 得到选择的列表．
        /// </summary>
        /// <param name="rpt1">需要在里面查找值的　repeater </param>
        /// <param name="controlID">checkbox 的　ID</param>
        /// <param name="hidControlID">保存值的 隐藏控件</param>
        /// <param name="needValue">设定是需要选中的还是未选中的</param>
        /// <returns></returns>
        public static string getSelectedValueForCheckBox(Repeater rpt1, string controlID, string hidControlID, bool needValue)
        {
            string IDList = "";
            foreach (RepeaterItem item1 in rpt1.Items)
            {
                HtmlInputCheckBox chkSelected = (HtmlInputCheckBox)item1.FindControl(controlID);
                if (chkSelected.Checked == needValue)
                {
                    HtmlInputHidden hidValueID = (HtmlInputHidden)item1.FindControl(hidControlID);
                    IDList += hidValueID.Value.ToString() + ",";
                }
            }

            if (IDList.Length > 0)
            {
                IDList = IDList.Substring(0, IDList.Length - 1);
            }
            return IDList;
        }

        /// <summary>
        /// 得到选择的列表．
        /// </summary>
        /// <param name="rpt1">需要在里面查找值的　repeater </param>
        /// <param name="controlID">checkbox 的　ID</param>
        /// <param name="hidControlID">保存值的 隐藏控件</param>
        /// <param name="needValue">设定是需要选中的还是未选中的</param>
        /// <returns></returns>
        public static string getSelectedValueForDataTable(DataTable dt, string checkField, string ValueField, string needValue)
        {
            string IDList = "";
            foreach (DataRow dr in dt.Rows)
            {
                string checkFieldValue = dr[checkField].ToString();
                if (checkFieldValue == needValue)
                {
                    string value = dr[ValueField].ToString();
                    IDList += value.ToString() + ",";
                }
            }

            if (IDList.Length > 0)
            {
                IDList = IDList.Substring(0, IDList.Length - 1);
            }
            return IDList;
        }

        public static string getSelectedValueForDataTable(DataTable dt, string ValueField)
        {
            string IDList = "";
            foreach (DataRow dr in dt.Rows)
            {
                string value = dr[ValueField].ToString();
                IDList += value.ToString() + ",";
            }

            if (IDList.Length > 0)
            {
                IDList = IDList.Substring(0, IDList.Length - 1);
            }
            return IDList;
        }



    }
}
